import { bannerAPI, groupsInfoAPI, getNewsAPI } from '@/api'
const state = {
  picture: [],
  groupsList: [],
  newsList: []

}
const mutations = {
  GETPICTURE(state, picture) {
    state.picture = picture
  },
  GROUPSLIST(state, groupsList) {
    state.groupsList = groupsList
  },
  NEWSLIST(state, newsList) {
    state.newsList = newsList
  }

}

const actions = {
  // 轮播图
  async confirmPicture(store) {
    try {
      const res = await bannerAPI()
      const picture = res.data.body
      store.commit('GETPICTURE', picture)
      return Promise.resolve(res)
    } catch (error) {
      return Promise.reject(error)
    }
  },
  // 租房小组
  async groupsInfo(store, data) {
    try {
      const res = await groupsInfoAPI(data)
      // console.log(res)
      const groupsList = res.data.body
      store.commit('GROUPSLIST', groupsList)
      return Promise.resolve(res)
    } catch (error) {
      return Promise.reject(error)
    }
  },
  // 最新资讯
  async newsInfo(store, id) {
    try {
      const res = await getNewsAPI(id)
      const newsList = res.data.body
      store.commit('NEWSLIST', newsList)
      return Promise.resolve(res)
    } catch (error) {
      return Promise.reject(error)
    }
  }
}

const getters = {

}

export default {
  state,
  mutations,
  actions,
  getters
}
